﻿using System;
using System.IO;
using System.Windows.Forms;

namespace RadioPlaylisterMediaLoader
{
    public partial class MainForm : Form
    {
        AppConfig appConfig;
        MediaLoaderApi api;
        public MainForm()
        {
            InitializeComponent();
            api = new MediaLoaderApi();
            api.MainForm = this;
            appConfig = new AppConfig();
            appConfig.SelectedFolder = System.Configuration.ConfigurationManager.AppSettings["selectedFolder"];
            selectedFolderTextBox.Text = appConfig.SelectedFolder;
        }

        private void selectFolderButton_Click(object sender, EventArgs e)
        {
            DialogResult result = folderBrowserDialog1.ShowDialog();
            if (result == DialogResult.OK)
            {
                String selectedPath = folderBrowserDialog1.SelectedPath;
                selectedFolderTextBox.Text = selectedPath;
                appConfig.SelectedFolder = selectedPath;
            }

        }
        
        private void processFileButton_Click(object sender, EventArgs e)
        {
            DirectoryInfo rootDirectory = new DirectoryInfo(appConfig.SelectedFolder);
            outputWindow.Text += "\nCreated root directory info object" + appConfig.SelectedFolder;
            api.processDirectory(rootDirectory);
        }

    }
}
